package com.tanhua.app.controller;

import com.tanhua.app.service.SmallVideosService;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.VideoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/smallVideos")
public class SmallVideosController {

    @Autowired
    private SmallVideosService videosService;

    /**
     * 发布视频
     * 接口路径：POST
     * 请求参数：
     * videoThumbnail：封面图
     * videoFile：视频文件
     */
    @PostMapping
    public ResponseEntity saveVideos(MultipartFile videoThumbnail, MultipartFile videoFile) throws IOException {
        videosService.saveVideos(videoThumbnail, videoFile);
        return ResponseEntity.ok(null);
    }

    /**
     * 视频列表
     */
    @GetMapping
    public ResponseEntity queryVideoList(@RequestParam(defaultValue = "1") Integer page,
                                         @RequestParam(defaultValue = "10") Integer pagesize) {
        PageResult<VideoVo> result = videosService.queryVideoList(page, pagesize);
        return ResponseEntity.ok(result);
    }


    @PostMapping("/{id}/like")
    public ResponseEntity like(@PathVariable("id") String id){

        Integer likeCount = videosService.likeCount(id);
        return ResponseEntity.ok(likeCount);
    }
}